#include <iostream>
#include <string>
#include <fstream>
#include <jsoncpp/json/json.h>

struct stu
{
    std::string name;
    int age;
    double weight;

public:
    void debug()
    {
        std::cout << name << std::endl;
        std::cout << age << std::endl;
        std::cout << weight << std::endl;
    }
};

// int main()
// {
//     struct stu zs = {"张三", 18, 70};
//     Json::Value root;
//     root["name"] = zs.name;
//     root["age"] = zs.age;
//     root["weight"] = zs.weight;
//     root["self"] = root;

//     Json::FastWriter writer;
//     std::string str = writer.write(root);

//     std::ofstream out("out.txt");
//     if (!out.is_open())
//         return 1;
//     out << str;

//     out.close();
//     return 0;
// }

int main()
{
    std::ifstream in("out.txt");
    if (!in.is_open())
        return 1;
    char buffer[1024];
    in.read(buffer, sizeof(buffer));
    in.close();
    std::cout << buffer << std::endl;

    std::string json_string = buffer;
    Json::Value root;
    Json::Reader reader;
    bool res = reader.parse(json_string, root);
    (void)res;

    struct stu zs;
    zs.name = root["name"].asString();
    zs.age = root["age"].asInt();
    zs.weight = root["weight"].asDouble();

    zs.debug();
}
